<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>WFS点要素调试</title>
    <!-- 1.引入依赖 -->
    <script src="https://lib.baomitu.com/ol3/4.6.5/ol.js"></script>
    <link rel="stylesheet" href="https://lib.baomitu.com/ol3/4.6.5/ol.css" />
  </head>
  <body>
    <!-- 2.创建map挂载点 -->
    <div id="map" style="width: 100vw; height: 100vh"></div>
    <script>
      // 3.初始化一个高德图层(初始化地图)
      const gaode = new ol.layer.Tile({
        title: '高德地图',
        source: new ol.source.XYZ({
          url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}',
          wrapX: false,
        }),
      })

      // 4.初始化openlayer地图
      var map = new ol.Map({
        target: 'map',
        layers: [gaode],
        view: new ol.View({
          center: ol.proj.fromLonLat([114.3, 30.5]),
          zoom: 5,
        }),
      })

      // ------------------添加test_3_1服务----------------
      // 5.创建矢量源以添加矢量要素
      var vectorSource = new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        url: 'http://localhost:8089/igs/rest/services/test3_1/WFSServer?service=WFS&version=1.1.0&request=GetFeature&typename=test3_1:t0&outputFormat=geojson&srsname=EPSG:4326&bbox=70,3,140,54,EPSG:4326',
        strategy: ol.loadingstrategy.all, // 一次性加载全部要素
      })
      // 6.创建矢量图层以添加矢量源
      var vectorLayer = new ol.layer.Vector({
        source: vectorSource,
      })
      // 7.添加样式
      var style = new ol.style.Style({
        image: new ol.style.Circle({
          radius: 8,
          fill: new ol.style.Fill({ color: 'green' }),
          stroke: new ol.style.Stroke({ color: '#000', width: 2 }),
        }),
      })
      vectorLayer.setStyle(style)
      // 8.调用地图以添加此图层
      map.addLayer(vectorLayer)
    </script>
  </body>
</html>
